#include "qwidgetmoveundocommand.h"

#include "qcommandobject.h"

using namespace CORELIB;

QWidgetMoveUndoCommand::QWidgetMoveUndoCommand(const QMap<QString, QVariant> &param, QUndoCommand *parent):
    QAbstractUndoCommand(param,parent)
{
}

int QWidgetMoveUndoCommand::id()const
{
    return WIDGET_MOVE_UNDO_ID;
}

bool QWidgetMoveUndoCommand::mergeWith(const QUndoCommand *other)
{
    QWidgetMoveUndoCommand* cmd=(QWidgetMoveUndoCommand*)other;

    QObject* obj=cmd->object();
    if(obj->property("widgetlist").toString()==m_object->property("widgetlist").toString())
    {
        QWidgetMoveUndoCommand *c1;
        QWidgetMoveUndoCommand *c2;
        for(int i=0;i<childCount();i++)
        {
            c1=(QWidgetMoveUndoCommand*)child(i);
            c2=(QWidgetMoveUndoCommand*)cmd->child(i);
            c1->object()->setProperty("new_value",c2->object()->property("new_value"));
        }
        return true;
    }
    else
    {
        return false;
    }
}
